//
//	jQuery Slug Generation Plugin by Perry Trinier (perrytrinier@gmail.com)
//  Licensed under the GPL: http://www.gnu.org/copyleft/gpl.html
	jQuery.fn.slug = function(options) {		
		this.each(function(i){
			var settings = {
				slug: 'slug', // Class used for slug destination input and span. The span is created on $(document).ready() 
				onInit: true
			};
			
			if(options) {
				jQuery.extend(settings, options);
			}			
			
			$this = jQuery(this);		
			
			makeSlug = function() {
					if($this.is("select"))
					{
						var slugcontent = $this.find('option:selected').text();
					}
					else
					{
						var slugcontent = $this.val();
					}
					
					var slugcontent_hyphens = slugcontent.replace(/\s/g,'-');
					var finishedslug = slugcontent_hyphens.replace(/[^a-zA-Z0-9\-]/g,'');
					jQuery(settings.slug).text(finishedslug.toLowerCase());
					
		
				}
	
				
			if(settings.onInit)
			{
				makeSlug();
			}		
			
			$this.change(makeSlug);
				
			return $this;
		});
	};